package cn.com.infcn.monitor.task.jvm;

import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;

import org.apache.log4j.Logger;

import cn.com.infcn.monitor.bean.IFCJVMRuntime;
import cn.com.infcn.monitor.task.BaseTask;
import cn.com.infcn.monitor.util.IFCBeanUtils;

/**
 * Java 虚拟机的运行时系统的管理接口。
 * @author jijs
 *
 */
public class JVMRuntimeTask implements BaseTask {

	private static final Logger LOGGER = Logger.getLogger(JVMRuntimeTask.class);

	@Override
	public IFCJVMRuntime execute() throws Exception {
		return jvmRuntime();
	}

	public IFCJVMRuntime jvmRuntime() {

		try {
			RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
			IFCJVMRuntime ifcRuntime = new IFCJVMRuntime();
			IFCBeanUtils.copyProperties(runtimeMXBean, ifcRuntime);

			return ifcRuntime;
		} catch (Exception e) {
			LOGGER.warn(e.getMessage(), e);
		}
		return null;
	}

	public static void main(String[] args) {
		JVMRuntimeTask task = new JVMRuntimeTask();
		System.out.println(task.jvmRuntime());
		
	}
	
	/*private void copyProperties(RuntimeMXBean runtimeMXBean, IFCJVMRuntime ifcRuntime){
		ifcRuntime.setBootClassPath(runtimeMXBean.getBootClassPath());
		ifcRuntime.setClassPath(runtimeMXBean.getClassPath());
		ifcRuntime.setInputArguments(runtimeMXBean.getInputArguments());
		ifcRuntime.setIsBootClassPathSupported(runtimeMXBean.isBootClassPathSupported());
		ifcRuntime.setLibraryPath(runtimeMXBean.getLibraryPath());
		ifcRuntime.setManagementSpecVersion(runtimeMXBean.getManagementSpecVersion());
		ifcRuntime.setName(runtimeMXBean.getName());
		ifcRuntime.setSpecName(runtimeMXBean.getSpecName());
		ifcRuntime.setSpecVendor(runtimeMXBean.getSpecVendor());
		ifcRuntime.setSpecVersion(runtimeMXBean.getSpecVersion());
		ifcRuntime.setStartTime(runtimeMXBean.getStartTime());
		ifcRuntime.setSystemProperties(runtimeMXBean.getSystemProperties());
		ifcRuntime.setUptime(runtimeMXBean.getUptime());
		ifcRuntime.setVmName(runtimeMXBean.getVmName());
		ifcRuntime.setVmVendor(runtimeMXBean.getVmVendor());
		ifcRuntime.setVmVersion(runtimeMXBean.getVmVersion());
	}*/
}
